package main

import "fmt"

// 嵌套结构体，拥有共同的属性

type school struct {
	name string
	class int
	addr string
}

type student1 struct {
	name string
	age int
	sex string
	school school
}

type student2 struct {
	name string
	age int
	sex string
	school			// 匿名结构体，调用的时候可以直接使用该结构体里面的方法
}

func main() {
	sch := school{
		name:  "枧头小学",
		class: 5,
		addr:  "枧头镇",
	}

	s1 := student1{
		name:   "小红",
		age:    18,
		sex:    "女",
		school: sch,
	}
	fmt.Println(s1.name, s1.age, s1.school.name)

	s2 := student2{
		name:   "小豪",
		age:    16,
		sex:    "男",
		school: sch,
	}
	fmt.Println(s2.name, s2.class)	//直接调用

}
